<template>
  <div>
    <div class="cartlist" v-for="(item, index) in cartlist" :key="index">
      <div class="left">{{ index + 1 }}</div>
      <div class="center">
        <img :src="item.image" alt="" />
      </div>
      <div class="right">
        <div class="top">{{ item.title }}</div>
        <div class="middle">商品描述：{{ item.desc }}</div>
        <div class="bottom">￥{{ item.lowPrice }}</div>
        <span class="num"
          >数量：<button id="decreace" @click="decreace(index)">-</button>
          {{ item.count }} <button @click="increace(index)">+</button></span
        >
      </div>
    </div>
  </div>
</template>
<script>
export default {
  name: "cartliastitem",
  data() {
    return {
      cartlist: this.$store.state.cartList,
    };
  },
  methods: {
    decreace(index) {
      if (this.cartlist[index].count <= 0) {
        this.cartlist[index].count = 1;
      }
      this.cartlist[index].count--;
    },
    increace(index) {
      this.cartlist[index].count++;
    },
  },
};
</script>
<style scoped>
.cartlist {
  font-size: 17px;
  align-items: center;
  justify-items: center;
  display: flex;
  padding-top: 15px;
  padding-bottom: 15px;
  border-bottom: 1px solid #ccc;
}
.left {
  padding: 10px;
}
img {
  width: 80px;
  height: 100px;
  display: block;
  border-radius: 5px;
}
.right {
  position: relative;
  left: 10px;
  display: flex;
  flex-direction: column;
  white-space: nowrap;
  height: 100px;
  overflow: hidden;
  text-overflow:ellipsis;
}
.right div {
  flex: 1;
  text-overflow:ellipsis;
}
.top {
  font-size: 18px;
  font-weight: 300px;
  position: relative;
  width: 280px;
  overflow: hidden;
  text-overflow:ellipsis;
}
.middle {
  position: relative;
  font-size: 15px;
  text-overflow: ellipsis;
  width: 280px;
  overflow: hidden;
  text-overflow:ellipsis;
}
.bottom {
  font-weight: 400px;
  position: relative;
  left: 10px;
  color: orangered;
}
.checkbox {
  width: 15px;
  height: 15px;
  color: #ff8198;
  border: 1px, solid, #ff8198;
  border-radius: 50%;
}
.num {
  width: 120px;
  text-align: center;
  position: absolute;
  bottom: 13px;
  left: 90px;
  background-color: #ff6d88;
  color: white;
  border-radius: 8px;
}
button {
  font-size: 20px;
  background-color: #ff6d88;
  outline: none;
  border: none;
  color: white;
}
</style>